const {Reply} = require('../db/model/index')

const createReply = async ({content, uid, contentId}) => {
  const result = await Reply.create({
    content,
    uid,
    contentId
  })

  const data = result.dataValues

  return data
}

const updateReply = async ({content, id}) => {
  const whereOpt = {
    id
  }
  const result = await Reply.update({
    content
  }, {
    where: whereOpt
  })

  const data = result.dataValues

  return data
}

const delReply = async (id) => {
  const result = await Reply.destroy({
    where: {
      id
    }
  })

  return result > 0
}

module.exports = {
  createReply,
  updateReply,
  delReply
}
